#######
# SPDX license identifier: MPL-2.0
#
# Copyright (C) 2011-2015, BMW AG
#
# This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
#
# This Source Code Form is subject to the terms of the
# Mozilla Public License (MPL), v. 2.0.
# If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# For further information see http://www.genivi.org/.
#######

project(musl)

add_library(${PROJECT_NAME} STATIC
    src/mq/mq_unlink.c
    src/mq/mq_open.c
    src/mq/mq_close.c
    src/mq/mq_send.c
    src/mq/mq_receive.c
    src/mq/mq_timedsend.c
    src/mq/mq_timedreceive.c
    src/ipc/shmctl.c
    src/ipc/shmdt.c
    src/ipc/shmget.c
    src/ipc/shmat.c
    src/ipc/semctl.c
    src/ipc/semget.c
    src/ipc/semop.c
    src/linux/timerfd.c
    )

target_include_directories(${PROJECT_NAME} PUBLIC include)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    set(RT_LIBRARY rt)
    set(SOCKET_LIBRARY "")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
    set(RT_LIBRARY "")
    set(SOCKET_LIBRARY "")
else()
    set(RT_LIBRARY "")
    set(SOCKET_LIBRARY socket)
endif()

if(HAVE_FUNC_PTHREAD_SETNAME_NP)
    add_definitions(-DDLT_USE_PTHREAD_SETNAME_NP)
    message(STATUS "Using pthread_setname_np API to set thread name")
else()
    message(STATUS "pthread_setname_np API not available on this platform")
endif()
#
#target_link_libraries(musl ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
#set_target_properties(musl PROPERTIES VERSION ${DLT_VERSION} SOVERSION ${DLT_MAJOR_VERSION})

install(TARGETS ${PROJECT_NAME}
    RUNTIME
        DESTINATION bin
        COMPONENT base
    LIBRARY
        DESTINATION ${CMAKE_INSTALL_LIBDIR}
        COMPONENT base
    ARCHIVE
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
        COMPONENT base)
